home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvidis / pxtopk_orig.vms-changes < prev    next >
Text File  |  1990-10-01  |  11KB  |  373 lines

  1. From: Robert Bittl BITTL AT DGATUM5P
  2. PXtoPK change file for Vax/VMS.
  3. Robert Bittl, Physik-Department TU Muenchen
  4. 21 Oct 86
  5.  7Dec87 JSL  .PKTOPX is now at Version 2.3.
  6.  
  7. @x
  8. \pageno=\contentspagenumber \advance\pageno by 1
  9. @y
  10. \pageno=\contentspagenumber \advance\pageno by 1
  11. \let\maybe=\iftrue
  12. \def\title{PXtoPK changes for Vax/VMS}
  13. @z
  14.      
  15. @x
  16. @d banner=='This is PXtoPK, Version 2.3'
  17. @y
  18. @d banner=='This is PXtoPK, Vax/VMS Version 2.3'
  19. @z
  20.      
  21. @x
  22. @d othercases == others: {default for cases not listed explicitly}
  23. @d endcases == @+end {follows the default case in an extended |case| statement}
  24. @y
  25. @d othercases == otherwise {Vax/VMS default for cases not listed explicitly}
  26. @d endcases == @+end {follows the default case in an extended |case| statement}
  27. @d real == double
  28. @z
  29.      
  30. @x
  31. @p program PXtoPK(input, output);
  32. @y
  33. @p
  34. @\@=[inherit('sys$library:starlet')]@>@\
  35. program PXtoPK(@!pk_file,@!pxl_file,@!input,@!output);
  36. @z
  37.      
  38. @x
  39. procedure initialize; {this procedure gets things started properly}
  40.   var i:integer; {loop index for initializations}
  41.   begin print_ln(banner);@/
  42. @y
  43. @<Procedures for initialization@>@\
  44. procedure initialize; {this procedure gets things started properly}
  45.   var i:integer; {loop index for initializations}
  46.   begin print_ln(banner);@/
  47.   @<Preset initial values@>@\
  48. @z
  49.      
  50. @x
  51. @!word_file=packed file of integer; {for pixel file words}
  52. @!byte_file=packed file of eight_bits ; {for packed file words}
  53. @y
  54. {later we'll define files that contain binary date}
  55. @z
  56.      
  57. @x
  58. @!pxl_file:word_file; {where the input comes from}
  59. @!pk_file:byte_file;  {where the final output goes}
  60. @y
  61. @!pxl_file:packed file of int_block; {where to input comes from}
  62. @!pk_file:packed file of byte_block; {where the final output goes}
  63. @z
  64.      
  65. @x
  66. begin reset(pxl_file,pxl_name);
  67. @y
  68. begin reset(pxl_file);
  69. @z
  70.      
  71. @x
  72. begin rewrite(pk_file,pk_name);
  73. @y
  74. begin rewrite(pk_file);
  75. @z
  76.      
  77. @x
  78. @!pk_loc:integer; {how many bytes have we sent?}
  79. @y
  80. @!pk_loc:integer; {how many bytes have we sent?}
  81. @!pk_count:integer; {number of bytes read from current block of |pk_file|}
  82. @z
  83.      
  84. @x
  85. pk_loc := 0 ;
  86. @y
  87. pk_loc := 0 ; pk_count := 0 ;
  88. @z
  89.      
  90. @x
  91. @p function pixel_integer : integer ;
  92. var i:integer;
  93. begin i := pxl_file^ ;
  94. get(pxl_file) ;
  95. eof_pixel:=eof(pxl_file);
  96. pixel_integer:=i;
  97. end;
  98. @y
  99. This routine is not needed, as we do the buffering directly in the
  100. pixel reading routine.
  101.      
  102. @ We also will need a procedure to flip the bytes around in case they are
  103. backwards (as they almost always will be.
  104.      
  105. @p function flip(mixed: integer): integer ;
  106.      
  107. type
  108.    select2=0..1 ;
  109.    eight_bits=[byte]0..255 ;
  110.      
  111. var
  112.    convert: record case select2 of
  113.       0:(int: integer) ;
  114.       1:(w_0, w_1, w_2, w_3: eight_bits) ;
  115.    end ;
  116.    temp: eight_bits ;
  117.      
  118. begin
  119.    convert.int := mixed ;
  120.    temp := convert.w_0 ;
  121.    convert.w_0 := convert.w_3 ;
  122.    convert.w_3 := temp ;
  123.    temp := convert.w_1 ;
  124.    convert.w_1 := convert.w_2 ;
  125.    convert.w_2 := temp ;
  126.    flip := convert.int ;
  127. end ;
  128. @z
  129.      
  130. @x
  131. @ @p procedure pk_byte(b : integer) ;
  132. begin
  133. if b < 0 then b := b + 256 ;
  134. pk_file^ := b ;
  135. put(pk_file) ;
  136. incr(pk_loc) ;
  137. end ;
  138. @y
  139. @ @p procedure pk_byte(b : integer) ;
  140. begin
  141. if b < 0 then b := b + 256 ;
  142. pk_file^[pk_count] := b ;
  143. incr(pk_count);
  144. if pk_count=VAX_block_length then begin
  145.    put(pk_file) ;
  146.    pk_count := 0 ;
  147. end;
  148. incr(pk_loc) ;
  149. end ;
  150. @z
  151.      
  152. @x
  153. var k:integer; {index for word moves}
  154. @y
  155. var k:integer; {index for word moves}
  156.     r:integer; {index for the pxl buffer}
  157. @z
  158.      
  159. @x
  160.    while not eof_pixel do begin
  161.       mem[k] := pixel_integer ;
  162.       k := k + 1 ;
  163.       if k > max_mem_size then
  164.          abort('PXtoPK memory size exceeded on load of pixel file!') ;
  165.    end ;
  166. @y
  167.    while not eof(pxl_file) do begin
  168.       if k + 128 > max_mem_size then
  169.          abort('PXtoPK memory size exceeded on load of pixel file!') ;
  170.       for r := 0 to 127 do begin
  171.          mem[k] := pxl_file^[r] ; k := k + 1 ;
  172.       end ;
  173.       get(pxl_file, @=error@>:=@=continue@>) ;
  174.    end ;
  175. @z
  176.      
  177. @x
  178.    if (mem[k] <> pxl_id) or (mem[0]<>pxl_id) then goto 9997 ;
  179. @y
  180.    if (mem[0]=flip(pxl_id)) then
  181.       for r := 0 to k do
  182.          mem[r] := flip(mem[r]) ;
  183.    if mem[0]<>pxl_id then goto 9997 ;
  184.    r := k ;
  185.    while mem[k] <> pxl_id do
  186.       k := k - 1 ;
  187.    if r-k > 140 then goto 9997 ;
  188. @z
  189.      
  190. @x
  191. @* Terminal communication.
  192. We must get the file names and determine whether output is to be in
  193. hexadecimal or binary.  To do this, we use the standard input path
  194. name.  We need a procedure to flush the input buffer.  For most systems,
  195. this will be an empty statement.  For other systems, a |print_ln| will
  196. provide a quick fix.  We also need a routine to get a line of input from
  197. the terminal.  On some systems, a simple |read_ln| will do.  Finally,
  198. a macro to print a string to the first blank is required.
  199.      
  200. @d flush_buffer == begin end
  201. @d get_line(#) == if eoln(input) then read_ln(input) ;
  202.    i := 1 ;
  203.    while not (eoln(input) or eof(input)) do begin
  204.       #[i] := input^ ;
  205.       incr(i) ;
  206.       get(input) ;
  207.    end ;
  208.    #[i] := ' '
  209.      
  210. @ @p procedure dialog ;
  211. var i : integer ; {index variable}
  212. buffer : packed array [1..name_length] of char; {input buffer}
  213. begin
  214.    for i := 1 to name_length do begin
  215.       pxl_name[i] := ' ' ;
  216.       pk_name[i] := ' ' ;
  217.    end;
  218.    print('Input file name:  ') ;
  219.    flush_buffer ;
  220.    get_line(pxl_name) ;
  221.    print('Output file name:  ') ;
  222.    flush_buffer ;
  223.    get_line(pk_name) ;
  224.    print_ln(' ') ;
  225. end ;
  226. @y
  227. @* Terminal communication.
  228. We must get the file names either from the command line or interactive.
  229. in the latter case we use the standard input path name.
  230.      
  231. @ The task of the procedure dialog is done by the system specific routine
  232. |Preset initial values|
  233. @z
  234.      
  235. @x
  236. initialize ;
  237. dialog ;
  238. @y
  239. initialize ;
  240. @z
  241.      
  242. @x
  243. write_postamble ;
  244. @y
  245. write_postamble ;
  246. while pk_count>0 do pk_byte(0);
  247. close(pk_file,@=disposition:=save@>,@=error:=continue@>);
  248. @z
  249.      
  250. @x
  251. This section should be replaced, if necessary, by changes to the program
  252. that are necessary to make \.{PXtoPK} work at a particular installation.
  253. Any additional routines should be inserted here.
  254. @^system dependencies@>
  255. @y
  256. Here are the remaining changes to the program
  257. that are necessary to make \.{PXtoPK} work on Vax/VMS.
  258.      
  259. @<Const...@>==
  260. @!VAX_block_length=512;
  261.      
  262. @ @<Types...@>==
  263. @!byte_block=packed array [0..VAX_block_length-1] of 0..255;
  264. @!int_block=packed array [0..127] of integer;
  265.      
  266. @ On Vax/VMS we need the following special definitions, types, variables
  267. and procedures to be able to get the file name from the command line,
  268. or to prompt for them.
  269.      
  270. @d VAX_status==@=status@>
  271. @d VAX_direct==@=direct@>
  272. @d VAX_fixed==@=fixed@>
  273. @d VAX_volatile==@=volatile@>
  274. @d VAX_immed==@=%immed @>
  275. @d VAX_external==@=external@>
  276. @d VAX_stdescr==@=%stdescr @>
  277. @d VAX_lib_get_foreign==@= lib$get_foreign@>
  278. @d VAX_length==@=length @>
  279. @d VAX_fab_type==@= FAB$TYPE @>
  280. @d VAX_rab_type==@= RAB$TYPE @>
  281. @d VAX_xab_type==@= XAB$TYPE @>
  282. @d VAX_fab_xab==@= FAB$L_XAB @>
  283. @d VAX_xab_nxt==@= XAB$L_NXT @>
  284. @d VAX_xab_cod==@= XAB$B_COD @>
  285. @d VAX_xab_fhc==@= XAB$C_FHC @>
  286. @d VAX_xab_ebk==@= XAB$L_EBK @>
  287. @d VAX_xab_ffb==@= XAB$W_FFB @>
  288.      
  289. @ @<Types...@>=
  290. @!sixteen_bits= 0..65535;
  291.      
  292. @ @<Glob...@>==
  293. @!command_line:packed array[1..300] of char;
  294. @!cmd_len:sixteen_bits;
  295. @!cmd_i:integer;
  296. @!file_name,@!def_file_name:varying [300] of char;
  297. @!ask,@!got_file_name: boolean;
  298.      
  299. @ @<Preset init...@>=
  300. cmd_i:=0;
  301. VAX_lib_get_foreign(command_line,,cmd_len,cmd_i);
  302. cmd_i:=1; while (cmd_i<=cmd_len) and (command_line[cmd_i]=' ') do incr(cmd_i);
  303. got_file_name:=cmd_i<=cmd_len;
  304. if got_file_name then
  305.         def_file_name:=substr(command_line,cmd_i,cmd_len-cmd_i+1);
  306.      
  307. if got_file_name then begin
  308.         if index(def_file_name,'.')<=index(def_file_name,']') then
  309.            file_name:=def_file_name+'.PXL'
  310.         else file_name:=def_file_name;
  311.         open(pxl_file,file_name,@=readonly@>,,VAX_direct,
  312.                 VAX_fixed,,@=error:=continue@>);
  313.         ask:=status(pxl_file)<>0;
  314.         if ask then write_ln('Couldn''t open ',file_name);
  315.         end
  316. else ask:=true;
  317. while ask do begin
  318.         got_file_name:=false;
  319.         write('PXL file: ');
  320.         if eof then goto 9999;
  321.         read_ln(file_name);
  322.         open(pxl_file,file_name,@=readonly@>,,VAX_direct,
  323.                 VAX_fixed,,@=error:=continue@>);
  324.         ask:=status(pk_file)<>0;
  325.         if ask then write_ln('Couldn''t open ',file_name);
  326.         end;
  327.      
  328. if got_file_name then begin
  329.         cmd_i:=1;
  330.         for cmd_len:=1 to def_file_name.VAX_length do
  331.                 if (def_file_name[cmd_len]=']')
  332.                 or (def_file_name[cmd_len]=':')
  333.                 then cmd_i:=cmd_len+1;
  334.         if cmd_i<=def_file_name.VAX_length then
  335.                 def_file_name:=substr(def_file_name,cmd_i,
  336.                         def_file_name.VAX_length-cmd_i+1);
  337.         if index(def_file_name,'.')=0 then file_name:=def_file_name+'.PK'
  338.         else if index(def_file_name,'PXL')=def_file_name.VAX_length-2 then begin
  339.                         def_file_name[def_file_name.VAX_length-1]:='K';
  340.                         file_name:=substr(def_file_name,
  341.                                           1,def_file_name.VAX_length-1);
  342.                         end
  343.                 else file_name:=def_file_name+'PK';
  344.         open(pk_file,file_name,@=new,disposition:=delete@>,
  345.                 @=error:=continue@>);
  346.         ask:=status(pk_file)>0;
  347.         if ask then write_ln('Couldn''t open ',file_name);
  348.         end
  349. else ask:=true;
  350. while ask do begin
  351.         write('PK file: ');
  352.         if eof then goto final_end;
  353.         read_ln(file_name);
  354.         if file_name.VAX_length=0 then file_name:='SYS$OUTPUT';
  355.         open(pk_file,file_name,@=new,disposition:=delete@>,
  356.                 @=error:=continue@>);
  357.         ask:=status(pk_file)>0;
  358.         if ask then write_ln('Couldn''t open ',file_name);
  359.         end;
  360.      
  361. @ Here is the library procedure that gets the user's command line.
  362.      
  363. @<Procedures for ...@>=
  364. [VAX_external] function VAX_lib_get_foreign(
  365.   VAX_stdescr cmdlin:[VAX_volatile] packed array [$l1..$u1:integer] of char
  366.         := VAX_immed 0;
  367.   VAX_stdescr prompt:[VAX_volatile] packed array [$l2..$u2:integer] of char
  368.         := VAX_immed 0;
  369.   var len : [VAX_volatile] sixteen_bits := VAX_immed 0;
  370.   var flag : [VAX_volatile] integer := VAX_immed 0)
  371.     :integer; extern;
  372. @z